// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var hashJump = require("../hash/hashJump");
	var validate = require("validate");
	var router = require("../hash/pageRouter");
	var imgSrc;
	var countId;
	var spaceId;
	var init = function(page) {
		spaceId = page.params.spaceId||base.getUrlParam("spaceId");
		initevent();
		getAdvert();
		getAdSpaceInfo();
		router.init();
	};
	var initevent = function() {
		//若未登录，则返回登陆页面
		if(base.getData("sid")==null||base.getData("sid")==""||base.getData("sid")==undefined){
			top.location.href="../login/login.html";
		}
		
		//修改顶部栏的选中状态
		$(".nav_hover", window.parent.document).removeClass("head_link_1");
		$("#company", window.parent.document).addClass("head_link_1");
		
		$(".button_layout").find("a").attr("arg","spaceId="+spaceId);
		
		$(".button_layout").on("click", "#edit_btn", function(){
			router.route("adModify/advertisement_modify.html?"+$(this).parent().attr('arg'));
		});
		
		$("#main").on("click", "#adDetailManage", function(){
			router.route("adManage/platform_main_advertisement_manager.html");
		});
	};
	//	获取已有的广告信息
	var getAdvert = function() {
		var displayimg = function(advert) {
			var str = "";
			var advert = advert;
			var fileUuid = advert.fileUuid;
			var fileName = advert.fileName;
			var link = advert.url;
			var sequenze = advert.seqNo;
			str += '<div class="ad_img_display_ok" adId="' + advert.adId + '">';
			str += '<div class="out_img_size">';
			str += '<div class="left_img_ f14">';
			str += '<img src="/finance/api/v1.0/downloadFile.file?fileUuid=' + fileUuid + '" style="width:120px;height:100px;" />';
			str += '</div>';
			str += '</div>';
			str += '<div class="right_choose_style">';
			str += '<div class="choose_img">';
			str += '<span class="title_set">图片名称：</span>';
			str += '<span class="w100">' + fileName + '</span>';
			str += '</div>';
			str += '<div class="choose_img">';
			str += '<span class="title_set">轮播顺序：</span>';
			str += '<span class="w30">' + sequenze + '</span>';
			str += '</div>';
			str += '<div class="link_addr">';
			str += '<span class="title_set">链接地址：</span>';
			str += '<div class="f14 url_set">' + link + '</div>';
			str += '</div>';
			str += '</div>';
			str += '<div class="clear"></div>';
			str += '</div>';
			$("#ad_list").append(str);
		}
		base.fnAjax({
			action: "inquireAdList.json", //接口名称
			oData: {
				spaceId: spaceId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var advert = data.datas;
					for (var i = 0; i < advert.length; i++) {
						var row = advert[i];
						displayimg(row);
					}
				}
			}
		});
	};
	//获取广告位信息
	var getAdSpaceInfo = function() {
		base.fnAjax({
			action: "inquireAdSpaceDetail.json", //接口名称
			oData: {
				spaceId: spaceId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					$("#ad_referenceNo").val(data.datas[0].referenceNo);
					$("#ad_name").val(data.datas[0].name);
					$("#ad_length").val(data.datas[0].length);
					$("#ad_width").val(data.datas[0].width);
					$("#ad_description").val(data.datas[0].description);
				}
			}
		});
	};
	return {
		init: init
	};
});